How do you perform migrations in EF Core?
312
20-May-2025
Utpal Vishwas
20-May-2025To perform migrations in EF Core, you use the EF Core CLI tools or Package Manager Console to:
Basic EF Core Migration Workflow
1. Install EF Core Tools (if needed)
For CLI:
2. Create Initial Migration
This creates a
Migrations/folder with a snapshot of the model and SQL instructions to create tables.3. Apply Migration to Database
This runs the migration and updates your database schema accordingly.
When Models Change
1. Modify your C# models or
DbContext.2. Add a new migration:
3. Apply it:
Full Example
Step 1: Define a model
Step 2: Define a DbContext
Step 3: Register DbContext
Step 4: Add & Apply Migration
Common Commands
dotnet ef migrations add <Name>dotnet ef database updatedotnet ef migrations removedotnet ef migrations listdotnet ef database dropNotes
Microsoft.EntityFrameworkCore.Designpackage.